<?php

/**
 * Created by PhpStorm.
 * User: Xzareth
 * Date: 26/04/14
 * Time: 12:48 PM
 */
class Secure
{
    private $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function isLoggedIn()
    {
        return (isset($_SESSION['id'])) ? true : false;
    }

    public function isAdmin() {
        $userDetails = $this->user->getUserInfo($_SESSION['id']);
        return  $userDetails['IsAdmin'];
    }

    public function adminOnly()
    {
        if ($this->isLoggedIn()) {
            $isAdmin = $this->isAdmin();

            if (!$isAdmin) {
                header("Location: index.php");
                exit();
            }
        } else {
            header("Location: login.php");
            exit();
        }
    }
} 